<header class="header navbar bg-white shadow">
  <div class="btn-group tool-button">
    <a class="btn btn-primary navbar-btn" href="/private/wx/sales/manage/info/<%=sales.id%>" data-pjax><i class="ti-angle-left"></i> 返回</a>
  </div>
</header>

<div class="content-wrap">
  <div class="wrapper" style="min-height:500px;">
    <section class="panel panel-form">
      <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
            action="/private/wx/sales/manage/info_addDo" method="post" >
        <input type="hidden" name="wxid" value="<%=sales.wxid%>">
        <input type="hidden" name="salesid" value="<%=sales.id%>">
        <div class="row mb10">
          <div class="col-lg-12">
            <div class="form-group">
              <label for="title" class="col-sm-2 control-label">标题</label>
              <div class="col-sm-8">
                <input type="text" id="title" class="form-control" name="title" data-parsley-required="true"
                       placeholder="标题">
              </div>
            </div>
            <div class="form-group">
              <label for="picurl" class="col-sm-2 control-label">小图片(300*300以内)</label>

              <div class="col-sm-8">
                <div id="queue"></div>
                <div class="input-group">
                  <input id="file_upload" name="file_upload" type="file" multiple="false">
                  <span class="input-group-btn">
                  <button class="btn btn-color current-time" type="button"
                          onclick="$('#file_upload').uploadifive('upload')">上传<i class="ti-upload ml5"></i></button>
                  </span>
                </div>
                <div id="img" style="padding: 5px;">
                </div>
                <input type="hidden" id="picurl" name="picurl" value="" >
              </div>
            </div>
            <div class="form-group">
              <label for="note" class="col-sm-2 control-label">内容</label>
              <div class="col-sm-8">
                <textarea name="note" id="note" style="height:220px;"></textarea>
              </div>
            </div>

          </div>
        </div>
        <div class="col-lg-3"></div>
        <div class="col-lg-6">
          <div class="form-group text-center">
            <label></label>
            <div>
              <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
            </div>
          </div>
        </div>
      </form>
    </section>

  </div>
</div>
<script language="JavaScript">
  function clearFile() {
    $("#img").html("");
    $("#picurl").val("");
  }
  $(document).ready(function () {
    var ue = new baidu.editor.ui.Editor({maximumWords:300});
    ue.render('note');
    $('#file_upload').uploadifive({
      'auto': false,
      'multi': false,
      'width': '100%',
      'height': '35',
      'buttonText': '请选择图片',
      'fileType': 'image/*',
      'fileSizeLimit': 1024,
      'queueSizeLimit': 1,
      'formData': {},
      'queueID': 'queue',
      'uploadScript': '/open/fileupload/image',
      'onUploadComplete': function (file, data) {
        data = JSON.parse(data);
        if (data.code == 0) {
          Toast.success(data.msg);
          $("#img").html("<img src='" + data.path + "' style='width:150px;'>");
          $("#picurl").val(data.path);
        } else {
          clearFile();
          Toast.error(data.msg);
        }
      },
      'onDrop': function (file, fileDropCount) {
        clearFile();
      },
      'onClearQueue': function (queue) {
        clearFile();
      },
      'onCancel': function () {
        clearFile();
      }
    });
    $('#addForm').ajaxForm({
      dataType: 'json',
      beforeSubmit: function (arr, form, options) {
        form.find("button:submit").button("loading");
      },
      success: function (data, statusText, xhr, form) {
        if (data.code == 0) {
          Toast.success(data.msg);
          //刷新父级菜单
          form.resetForm();
        } else {
          Toast.error(data.msg);
        }
        form.find("button:submit").button("reset");
      }
    });
  });
</script>
